#include "Box3D.hpp"
#include <math.h>

using namespace klasPhysics;
// ====================  Constructors ===================
Box3D::Box3D()
{
	m_Position = Vector3D();
}

Box3D::Box3D(const Box3D& box)
{
	m_Position = box.m_Position;
	m_Dimensions = box.m_Dimensions;
}

Box3D::Box3D(const Vector3D &loc, const Vector3D &dim):
	m_Position(loc), m_Dimensions(dim)
{}



// ==================== Return Functions =================
inline Vector3D Box3D::Dimensions() const
{
	return m_Dimensions;
}

inline Vector3D Box3D::Pos() const
{
	return m_Position;
}

// ================= Set Functions ===================
inline void Box3D::SetDimensions(const Vector3D &dim)
{
	m_Dimensions = dim;
}

inline void Box3D::SetPosition(const Vector3D &pos)
{
	m_Position = pos;
}

// ================== Other Functions ===================
bool Box3D::Intersects(const Box3D& box)
{
	Real left1, left2;
	Real right1, right2;
	Real up1, up2;
	Real down1, down2;
	Real top1, top2;
	Real bottom1, bottom2;

	left1 = this->Pos().x;
	left2 = box.Pos().x;
	
	right1 = this->Pos().x + this->m_Dimensions.x;
	right2 = box.Pos().x + box.Dimensions().x;

	up1 = this->Pos().y;
	up2 = box.Pos().y;

	down1 = this->Pos().y + this->m_Dimensions.y;
	down2 = box.Pos().y + box.Dimensions().y;

	top1 = this->Pos().z;
	top2 = box.Pos().z;

	bottom1 = this->Pos().y + this->m_Dimensions.y;
	bottom2 = box.Pos().y + box.Dimensions().y;

	if (bottom1 < top2) return false;
	if (top1 > bottom2) return false;

	if(right1 < left2) return false;
	if(left1 > right2) return false;

	if(up1 < down2) return false;
	if(down1 > up2) return false;

	return true;
}